﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class RepaymentPlanItem : IAccessible<P_RepaymentPlanItem, RepaymentPlanItem>, ILogicEntity<P_RepaymentPlanItem, RepaymentPlanItem>
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public int PlanID { get; set; }
        public int CycleNumber { get; set; }
        public DateTime RepaymentDate { get; set; }
        public decimal RepaymentInterest { get; set; }
        public decimal RepaymentPrincipal { get; set; }
        public decimal ReMainPrincipal { get; set; }
        public decimal ReMainInterest { get; set; }
        public RepaymentStatus Status { get; set; }
        public DateTime RepaymentTime { get; set; }
        public int RepaymentType { get; set; }
        public int AmountOperationID { get; set; }
        public int ProjectId { get; set; }
        public int PolicyId { get; set; }
        //与表结构无关
        public int SpanDay { get; set; }

        protected override void Covariant(P_RepaymentPlanItem model)
        {
            if (model != null)
            {
                this.AmountOperationID = model.AmountOperationID;
                this.CycleNumber = model.CycleNumber;
                this.ID = model.ID;
                this.PlanID = model.PlanID;
                this.RepaymentDate = model.RepaymentDate;
                this.RepaymentInterest = model.RepaymentInterest;
                this.RepaymentPrincipal = model.RepaymentPrincipal;
                this.ReMainPrincipal = model.ReMainPrincipal;
                this.ReMainInterest = model.ReMainInterest;
                this.RepaymentTime = model.RepaymentTime;
                this.RepaymentType = model.RepaymentType;
                this.Status = (RepaymentStatus)model.Status;
                this.UserName = model.UserName;
                this.PolicyId = model.PolicyId;
                this.ProjectId = model.ProjectId;
            }
        }

        protected override P_RepaymentPlanItem Inverter(RepaymentPlanItem model)
        {
            if (model != null)
            {
                return new P_RepaymentPlanItem()
                {
                    AmountOperationID = model.AmountOperationID,
                    CycleNumber = model.CycleNumber,
                    ID = model.ID,
                    PlanID = model.PlanID,
                    RepaymentDate = model.RepaymentDate,
                    RepaymentInterest = model.RepaymentInterest,
                    RepaymentPrincipal = model.RepaymentPrincipal,
                    ReMainPrincipal = model.ReMainPrincipal,
                    ReMainInterest = model.ReMainInterest,
                    RepaymentTime = model.RepaymentTime,
                    RepaymentType = model.RepaymentType,
                    Status = (int)model.Status,
                    UserName = model.UserName,
                    PolicyId = model.PolicyId,
                    ProjectId=model.ProjectId
                };
            }
            return null;
        }

        public RepaymentPlanItem Set(P_RepaymentPlanItem dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
